<?php
class User_Service_Common extends My_Service{
	
	#登录成功处理
	function setLogin($userInfo, $rememberMe=0){
		$user = $userInfo;
		unset($userInfo['pwd']);
		$session = new My_Session_Namespace("login");
		$session->user = $userInfo;
		if($rememberMe){
			$autoLoginData['uid'] = $user['id'];
			$autoLoginData['pwd'] = $user['pwd'];
			$autoLoginData = serialize($autoLoginData);
			$option = My_Config::getInstance()->getInit();
			$key = $option['auto_login_key'];
			$autoLoginData = My_Tool::authcode($autoLoginData,$key, "ENCODE");
			$config = My_Config::getInstance()->getInit();
			$sessionDomain = $config['session']['domain'];
			My_Tool_Cookie::set("autologin", $autoLoginData, 60*60*24*365, "/", $sessionDomain);
		}
		
		return true;
	}
	
	#获取登录
	function getLogined(){
		$session = new My_Session_Namespace("login");
		return $session->user;
	}
	
	#更新session
	function updateUserSession($uid){
		#更新session
		$userinfo = User::dao()->getInfo()->get(array("id"=>$uid));
		unset($userinfo['pwd']);
		$session = new My_Session_Namespace("login");
		$session->user = $userinfo;
		return true;
	}
	
	#判断是否是管理员
	function isAdmin($uid){
		if(!$uid) return false;
		$userinfo = User::dao()->getInfo()->get(array("id"=>$uid));
		if(!$userinfo) return false;
		if($userinfo['role'] == 9) return true;
		return false;
	}
	
}